import store from "@/store/index";
import { Local, Session } from "@/utils/storage";
import type { Directive, DirectiveBinding } from "vue";
interface ElType extends HTMLElement {
  copyData: string | number;
  __handleClick__: any;
}
const Permission: Directive = {
  mounted(el: ElType, binding: DirectiveBinding) {
    const { value } = binding;
    const sessionStorages: any = sessionStorage;
    const currentPath: any = sessionStorages.getItem("currentPath");
    const permis = store.getters.getUserInfo?.menuList ?? [];
    //当前路径拼权限
    const currnetPers = `${currentPath}:${value}`;

    const newPermis: any = [];
    permis &&
      permis.forEach((i: any) => {
        if (i.viewFlag) newPermis.push(`${i.path}:viewFlag`);
        if (i.modifyFlag) newPermis.push(`${i.path}:modifyFlag`);
        if (i.createFlag) newPermis.push(`${i.path}:createFlag`);
        if (i.removeFlag) newPermis.push(`${i.path}:removeFlag`);
        if (i.upload) newPermis.push(`${i.path}:upload`);
        const otherPers = i.otherAuth;
        if (otherPers && otherPers.length) {
          otherPers.forEach((j: any) => {
            newPermis.push(`${i.path}:${j}`);
          });
        }

      });

    // console.log("是否permission：", currnetPers, newPermis, !newPermis.includes(currnetPers));
    // // consolelog('permis:', permis, 'currnetPers:', currnetPers, newPermis, newPermis.indexOf(currnetPers));
    if (!newPermis.includes(currnetPers)) el.style.display = "none";
  },
};
export default Permission